<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="applicationList" @selection-change="handleSelectionChange">
      <el-table-column label="申办人数" align="center" prop="sum" />
      <el-table-column label="报送日期" align="center" prop="sendTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sendTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="考试参加人数" align="center" prop="examSum" />
      <el-table-column label="考试类别" align="center" prop="examKind">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.exam_kind" :value="scope.row.examKind"/>
        </template>
      </el-table-column>
      <el-table-column label="考试地点" align="center" prop="examPlace">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.exam_place" :value="scope.row.examPlace"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220px">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="primary"
            style="width: 40px;"
            @click="handleUpdateCheck(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="primary"
            style="width: 60px;"
            @click="getExamApplicationStudentInfo(scope.row)"
          >学生信息</el-button>
          <el-button
            size="mini"
            type="success"
            style="width: 40px; margin-top: 10px;"
            @click="gaizhang(scope.row)"
          >盖章</el-button>
  
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="opencheck" width="1200px" append-to-body>
      <el-form :inline = "true" ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="申办人数" prop="sum">
          <el-input v-model="form.sum" placeholder="请输入申办人数" />
        </el-form-item>
        <el-form-item label="报送日期" prop="sendTime">
          <el-date-picker clearable
            v-model="form.sendTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择报送日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="考试参加人数" prop="examSum">
          <el-input v-model="form.examSum" placeholder="请输入考试参加人数" />
        </el-form-item>
        <el-form-item label="考试类别" prop="operationType">
          <el-select v-model="form.examKind" placeholder="请选择考试类别">
            <el-option
              v-for="dict in dict.type.exam_kind"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考试地点" prop="examPlace">
          <el-select v-model="form.examPlace" placeholder="考试地点">
            <el-option
              v-for="dict in dict.type.exam_place"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item  label="理论考试开始时间" prop="examStartTime">
          <el-date-picker clearable
            v-model="form.examStartTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择理论考试开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item  label="理论考试结束时间" prop="examEndTime">
          <el-date-picker clearable
            v-model="form.examEndTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择理论考试结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item  label="理论补考开始时间" prop="reviewStartTime">
          <el-date-picker clearable
            v-model="form.reviewStartTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择理论补考开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item  label="理论补考结束时间" prop="reviewEndTime">
          <el-date-picker clearable
            v-model="form.reviewEndTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择理论补考结束时间">
          </el-date-picker>
        </el-form-item>


        <el-form-item v-if="form.qualifiedType == 107" label="实操考试开始时间" prop="operationExamStartTime">
          <el-date-picker clearable
            v-model="form.operationExamStartTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="实操考试开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item v-if="form.qualifiedType == 107" label="实操考试结束时间" prop="operationExamEndTime">
          <el-date-picker clearable
            v-model="form.operationExamEndTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="实操考试结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item v-if="form.qualifiedType == 107" label="实操补考开始时间" prop="operationReviewStartTime">
          <el-date-picker clearable
            v-model="form.operationReviewStartTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="实操补考开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item v-if="form.qualifiedType == 107" label="实操补考结束时间" prop="operationReviewEndTime">
          <el-date-picker clearable
            v-model="form.operationReviewEndTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="实操补考结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="培训计划申请" prop="trainplanApplication">
          <file-upload v-model="form.trainplanApplication"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="check">确 定</el-button>
  
      </div>
    </el-dialog>
    
  </div>
</template>

<script>
import { listApplication, getApplication, delApplication, addApplication, updateApplication, gaizhang1ExamApplication } from "@/api/adminExamkaoshijigou/application";

export default {
  name: "Application",
  dicts: ['exam_place', 'exam_kind', 'jingbanren', "fuzeren"],
  data() {
    return {
      opencheck: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 审批考试申请表格数据
      applicationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examKind: null,
        examPlace: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  watch: {
   $route(to, from) {
       window.location.reload(); //监测到路由发生跳转时刷新一次页面
   },
},
  methods: {
    // 查看学生信息
    getExamApplicationStudentInfo(row) {
      const id = row.id || this.ids
      window.location.href = "../exam/examApplicationApprovalInfo?examApplicationId=" + id; 
    },
    check() {
      this.opencheck = false;
    },
    handleUpdateCheck(row) {
      this.reset();
      const id = row.id || this.ids
      getApplication(id).then(response => {
        this.form = response.data;
        this.opencheck = true;
        this.title = "查看审批考试申请";
      });
    },
    /** 查询审批考试申请列表 */
    getList() {
      this.loading = true;
      listApplication(this.queryParams).then(response => {
        this.applicationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        applicationUnitSheet: null,
        unitHeader: null,
        unitManager: null,
        sum: null,
        sendTime: null,
        examSum: null,
        examKind: null,
        examPlace: null,
        examStartTime: null,
        examEndTime: null,
        reviewStartTime: null,
        reviewEndTime: null,
        operationExamStartTime: null,
        operationExamEndTime: null,
        operationReviewStartTime: null,
        operationReviewEndTime: null,
        auditId: null,
        approvalId: null,
        examOperationSheet: null,
        approvalProcessSign: null,
        createTime: null,
        updateTime: null,
        isDeleted: null,
        createId: null,
        updateId: null,
        classTerm: null,
        isSubmit: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加审批考试申请";
    },
    /** 修改按钮操作 */
    gaizhang(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确定盖章？').then(function() {
        return gaizhang1ExamApplication(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("盖章成功");
      }).catch(() => {});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateApplication(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApplication(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除审批考试申请编号为"' + ids + '"的数据项？').then(function() {
        return delApplication(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('adminExamkaoshijigou/application/export', {
        ...this.queryParams
      }, `application_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
